<?php if ( ! defined('BASEPATH')) exit('No direct script access allowed');

class Exercises_model extends MY_Model
{
    public function __construct()
    {
        parent::__construct();
    }

    public function getMyExricisesList($fields = ' * ',$per_page, $limit, $filter)
    {
    	$where = " ";
        if($filter['departmentid']){
            $where .= " AND examinationDept = {$filter['departmentid']}";
        }
    	$limit = " limit {$per_page},{$limit}";

        $sql = "SELECT {$fields} FROM tr_test_paper WHERE 1 {$where}  ORDER BY createTime DESC {$limit} ";
        $query = $this->db->query($sql);
        $result =$query->result_array();
        return $result;
    }


    public function getMyExricisesListCnt($filter)
    {
        $where = " ";
        if($filter['departmentid']){
            $where .= " AND departmentID = {$filter['departmentid']}";
        }
        $sql = "SELECT paperID FROM tr_test_paper WHERE 1 {$where}";
        $query = $this->db->query($sql);
        return $query->num_rows();
    }

    public function getPaperAnswerInfo($paperID){
        $sql = "select paper.paperID,question.questionID,question.questionType,answer.answer from tr_test_paper as paper,tr_test_question as question,tr_question_answer as answer where paper.paperID = question.paperID and question.questionID=answer.questionID and paper.paperID=".$paperID;
        $result = $this->_geQuerySql($sql);
        return $result;
    }

    public function getWrongQuestion($accountID,$departmentid,$per_page,$limit){
        $limit = " limit {$per_page},{$limit}";
        $sql = "select mywrong.*,question.questionTile,question.questionType,myoption.optionTitle from tr_wrong_question as mywrong ,tr_test_question as question,tr_question_option as myoption where mywrong.questionID=question.questionID and question.questionID=myoption.questionID and mywrong.questionID in(select questionID from (select questionID from tr_wrong_question as qwrong where qwrong.userID=".$accountID." and qwrong.departmentID=".$departmentid." order by qwrong.questionID DESC {$limit}) as tmp)";
        $result = $this->_geQuerySql($sql);
        return $result;
    }
    public function getWrongQuestionCnt($accountID,$departmentid){
        $sql = "select count(*) from tr_wrong_question as mywrong where mywrong.userID=".$accountID." and mywrong.departmentID=".$departmentid;
        $query = $this->db->query($sql);
        return $query->num_rows();
    }

    
}

/* End of file Document_model.php */
/* Location: ./application/models/document_model.php */